package com.example.orderanduserbeta;

import org.json.JSONObject;

import java.util.Iterator;
import java.util.Map;
import java.util.Stack;

public class Zhuan {
    public static void JsonToMap(Stack<JSONObject> stObj, Map<String, Object> resultMap)   {

        if(stObj == null && stObj.pop() == null){
            return ;
        }
        JSONObject json = stObj.pop();
        Iterator it = json.keys();
        while(it.hasNext()){
            String key = (String) it.next();
            //得到value的值
            Object value = json.get(key);
            //System.out.println(value);
            if(value instanceof JSONObject)
            {
                stObj.push((JSONObject)value);
                //递归遍历
                JsonToMap(stObj,resultMap);
            }
            else {
                resultMap.put(key, value);
            }
        }
    }
}
